package com.foolrabbit.springbootlearning.event.publisher;

import com.foolrabbit.springbootlearning.event.entity.Baby;
import com.foolrabbit.springbootlearning.event.entity.CryEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * 宝宝哭事件发布者
 */
@Component
public class BabyCryPublisher {
    @Autowired
    ApplicationContext applicationContext;

    public void publish(Baby baby)
    {
        CryEvent cryEvent = new CryEvent(this, baby.getName());
        applicationContext.publishEvent(cryEvent);
    }
}
